package com.corechina.apex_osswords.common;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: apex_osswords
 * @description: 提醒日期工具类
 * @author: cc
 * @create: 2023-03-13 14:22
 **/
public class RemindDateUtils {

    public static List<LocalDate> getRemindList(LocalDate beginDate, LocalDate endDate, Integer type, Integer frequency) {
        //type: 1 year 2 month 3 week 4 day
        List<LocalDate> dateList = new ArrayList<>();
        LocalDate nexDate = beginDate;
        dateList.add(nexDate);
        if (type.equals(1)) {
            for (int i = 0; i < DateUtil.yearsBetween(beginDate, endDate) / frequency; i++) {
                nexDate = nexDate.plusYears(frequency);
                dateList.add(nexDate);
            }
        } else if (type.equals(2)) {
            for (int i = 0; i < DateUtil.monthsBetween(beginDate, endDate) / frequency; i++) {
                nexDate = nexDate.plusMonths(frequency);
                if (nexDate.isAfter(endDate)) {
                    continue;
                }
                dateList.add(nexDate);
            }
        } else if (type.equals(3)) {
            for (int i = 0; i < DateUtil.daysBetween(beginDate, endDate) / 7 / frequency; i++) {
                nexDate = nexDate.plusWeeks(frequency);
                dateList.add(nexDate);
            }
        } else if (type.equals(4)) {
            for (int i = 0; i < DateUtil.daysBetween(beginDate, endDate) / frequency; i++) {
                nexDate = nexDate.plusDays(frequency);
                dateList.add(nexDate);
            }
        }
        return dateList;
    }
}
